import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import savgol_filter

df = pd.read_csv('../../data/FujinNDVI_10D_22.csv')
# print(df)

time = df.iloc[:,0].values
data1 = df.iloc[:,1].values
data2 = df.iloc[:,2].values
data3 = df.iloc[:,3].values
# print(time)

# 应用Savitzky-Golay滤波
window_length = 11  # 窗口长度，必须是奇数
polyorder = 2  # 多项式阶数
filtered_data1 = savgol_filter(data1, window_length, polyorder)
filtered_data2 = savgol_filter(data2, window_length, polyorder)
filtered_data3 = savgol_filter(data3, window_length, polyorder)

# # 绘制原始数据和滤波后的数据
# plt.figure(figsize=(12, 8))
#
# plt.subplot(3, 1, 1)
# plt.plot(time, data1, label='Original Data 1')
# plt.plot(time, filtered_data1, label='Filtered Data 1', color='red')
# plt.legend()
# plt.title('Data 1')
#
# plt.subplot(3, 1, 2)
# plt.plot(time, data2, label='Original Data 2')
# plt.plot(time, filtered_data2, label='Filtered Data 2', color='red')
# plt.legend()
# plt.title('Data 2')
#
# plt.subplot(3, 1, 3)
# plt.plot(time, data3, label='Original Data 3')
# plt.plot(time, filtered_data3, label='Filtered Data 3', color='red')
# plt.legend()
# plt.title('Data 3')
#
# plt.tight_layout()
# plt.show()

# 绘制滤波后的曲线
plt.figure(figsize=(10, 6))

# 绘制滤波后的数据1
plt.plot(time, filtered_data1, label='Maize', color='blue')

# 绘制滤波后的数据2
plt.plot(time, filtered_data2, label='Rice', color='green')

# 绘制滤波后的数据3
plt.plot(time, filtered_data3, label='Soybean', color='red')

# 添加图例
plt.legend()

# 添加标题和轴标签
plt.title('Filtered Time Series Data')
plt.xlabel('Time')
plt.ylabel('Value')

# 显示图形
plt.show()

